package servlet;

import pojo.Brand;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet(name = "DeletesServlet", value = "/DeletesServlet")
public class DeletesServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String checkid = request.getParameter("checkId");
        System.out.println(checkid);
        String[] str=checkid.split(",");
        int[] ids=new int[str.length];
        if (str.length>0){
            for (int i = 0; i<str.length;i++){
                ids[i]=Integer.parseInt(str[i]);
            }
        }
            try {
                for (int id : ids){
                    Brand.deleteByIds(id);
                }
                response.sendRedirect("SelectAllServlet");
            }catch (Exception e){
                e.printStackTrace();
            }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
